package com.yowasa.xiuxian.engine.travel.adventure;

import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Sets;
import com.yowasa.xiuxian.engine.CommonEngine;
import com.yowasa.xiuxian.engine.item.ItemInterface;
import com.yowasa.xiuxian.engine.travel.AdventureInterface;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.MapEnum;
import com.yowasa.xiuxian.entity.enums.QualityEnum;
import com.yowasa.xiuxian.entity.enums.RefreshType;
import com.yowasa.xiuxian.entity.po.XiuxianTransactPO;
import com.yowasa.xiuxian.mapper.XiuxianTransactMapper;
import com.yowasa.xiuxian.service.helper.ResourceHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 尚武之风 一次刷新仅能被触发一次
 * 上架n本洪天秘典
 */
@Component
public class ShangWuZhiFeng implements AdventureInterface {

    @Autowired
    private XiuxianTransactMapper xiuxianTransactMapper;
    @Autowired
    private ResourceHelper resourceHelper;

    @Override
    public Set<MapEnum> limitMaps() {
        //洪天城only
        return Sets.newHashSet(MapEnum.MENG_DE_CHENG);
    }

    public boolean limitCheck(UserBO user) {
        return resourceHelper.checkHaveResource(user.getGuildId(), this.getClass().getName(), RefreshType.JIU_XING);
    }

    @Override
    public String exec(UserBO user) {
        resourceHelper.useResource(user.getGuildId(), this.getClass().getName());

        ItemInterface item = CommonEngine.ITEM_MAP.get("西风秘典");

        XiuxianTransactPO xiuxianTransact = new XiuxianTransactPO();
        xiuxianTransact.setStatus(1);
        xiuxianTransact.setItemNum(1);
        xiuxianTransact.setItemName(item.getName());
        xiuxianTransact.setAccountId(0L);
        xiuxianTransact.setItemPrice(5000);
        xiuxianTransact.setItemType(item.getType().getId());
        xiuxianTransact.setItemDesc(item.desc());
        xiuxianTransact.setItemAttr(item.attr(QualityEnum.LIANG));
        xiuxianTransact.setNowPrice(3000);
        xiuxianTransact.setNowAccount(0L);
        XiuxianTransactPO xiuxianTransacta = new XiuxianTransactPO();
        XiuxianTransactPO xiuxianTransactb = new XiuxianTransactPO();
        BeanUtil.copyProperties(xiuxianTransact,xiuxianTransacta);
        BeanUtil.copyProperties(xiuxianTransact,xiuxianTransactb);
        xiuxianTransactMapper.insert(xiuxianTransact);
        xiuxianTransactMapper.insert(xiuxianTransacta);
        xiuxianTransactMapper.insert(xiuxianTransactb);
        return "蒙德西风骑士团对外发售了3本西风秘典,现于交易行拍卖";
    }


}
